package com.manage.system.web.controller;

import com.manage.common.core.result.JsonResult;
import com.manage.common.log.annotation.OperateLog;
import com.manage.common.log.enums.BusinessType;
import com.manage.common.permissions.annotation.HasPermissions;
import com.manage.system.api.entity.SysLoginLog;
import com.manage.system.api.request.log.LoginLogQueryParam;
import com.manage.system.api.service.ISysLoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangqing
 * @description 系统访问日志控制层
 * @date 2021/4/26 8:00 下午
 */
@RestController
@RequestMapping("/login-log")
@AllArgsConstructor
@Api(tags = "系统访问日志", value = "SysLoginLogController")
public class SysLoginLogController {

    private final ISysLoginLogService sysLoginLogService;

    @ApiOperation("添加访问日志")
    @PostMapping(value = "/addLoginLog")
    public void addLoginLog(@RequestBody SysLoginLog sysLoginLog){
        sysLoginLogService.addLoginLog(sysLoginLog);
    }

    @ApiOperation("(分页)查询登录日志")
    @PostMapping(value = "/findLoginLogPage")
    public JsonResult findLoginLogPage(@RequestBody LoginLogQueryParam loginLogQueryParam){
        return sysLoginLogService.findLoginLogPage(loginLogQueryParam);
    }

    @ApiOperation("批量删除登录日志")
    @DeleteMapping("/batchDelLoginLog")
    @HasPermissions("log:loginLog:remove")
    @OperateLog(title = "删除登录日志",module = "登录日志",businessType = BusinessType.DELETE)
    public JsonResult batchDelLoginLog(@RequestBody List<Long> loginLogIds) {
        return sysLoginLogService.batchDelLoginLog(loginLogIds);
    }

    @ApiOperation("删除全部登录日志")
    @DeleteMapping("/delAllLoginLog")
    @HasPermissions("log:loginLog:remove")
    @OperateLog(title = "删除全部登录日志",module = "登录日志", businessType = BusinessType.DELETE)
    public JsonResult delAllLoginLog() {
        return sysLoginLogService.delAllLoginLog();
    }

    @ApiOperation("删除登录日志")
    @DeleteMapping("/delOneLoginLog/{loginLogId}")
    @HasPermissions("log:loginLog:remove")
    @OperateLog(title = "根据ID,删除单个登录日志", module = "登录日志",businessType = BusinessType.DELETE)
    public JsonResult delOneLoginLog(@PathVariable Long loginLogId) {
        return sysLoginLogService.delOneLoginLog(loginLogId);
    }
}
